package along.com.myboxugu.activity;

import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.view.menu.MenuView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import along.com.myboxugu.R;
import along.com.myboxugu.fragment.CourseFragment;
import along.com.myboxugu.fragment.ExerciseFragment;
import along.com.myboxugu.fragment.MyFragment;

public class MainActivity extends AppCompatActivity {
  FragmentManager fragmentManager;
    FragmentTransaction fragmentTransaction;
    ImageView courseImg;
    ImageView exerciseImg;
    ImageView myImg;
    TextView  courseTv;
    TextView  exerciseTv;
    TextView  myTv;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //course=findViewById(R.id.)
        courseImg= (ImageView) findViewById(R.id.course_one);
        exerciseImg= (ImageView) findViewById(R.id.exercise_one);
        myImg= (ImageView) findViewById(R.id.my_one);
        courseTv= (TextView) findViewById(R.id.course_Tv);
        exerciseTv= (TextView) findViewById(R.id.exercise_Tv);
        myTv= (TextView) findViewById(R.id.my_Tv);

        fragmentManager = getFragmentManager(); //获取方法
        fragmentTransaction = fragmentManager.beginTransaction(); //获取开始事物
        fragmentTransaction.add(R.id.fragment,new CourseFragment()); //创建显示
        fragmentTransaction.commit();//提交
    }

    //注意事项：1,方法添加参数View view
    //2,创建显示后用replay方法获取Fragment
    //3,用commit提交
    public  void  course(View view){
        courseTv.setTextColor(Color.parseColor("#ACCCF4"));
        courseImg.setImageResource(R.drawable.main_course_icon_selected);
        exerciseTv.setTextColor(Color.parseColor("#9C9C9C"));
        exerciseImg.setImageResource(R.drawable.main_exercises_icon);
        myTv.setTextColor(Color.parseColor("#9C9C9C"));
        myImg.setImageResource(R.drawable.main_my_icon);

        fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.replace(R.id.fragment,new CourseFragment());
        fragmentTransaction.commit();
    }
    public void  exercise(View view){
        exerciseTv.setTextColor(Color.parseColor("#ACCCF4"));
        exerciseImg.setImageResource(R.drawable.main_exercises_icon_selected);
        courseTv.setTextColor(Color.parseColor("#9C9C9C"));
        courseImg.setImageResource(R.drawable.main_course_icon);
        myTv.setTextColor(Color.parseColor("#9C9C9C"));
        myImg.setImageResource(R.drawable.main_my_icon);

        fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.replace(R.id.fragment,new ExerciseFragment());
        fragmentTransaction.commit();
    }

    public void  my(View view){
        myTv.setTextColor(Color.parseColor("#ACCCF4"));
        myImg.setImageResource(R.drawable.main_my_icon_selected);//selected挑选
        exerciseTv.setTextColor(Color.parseColor("#9C9C9C"));
        exerciseImg.setImageResource(R.drawable.main_exercises_icon);
        courseTv.setTextColor(Color.parseColor("#9C9C9C"));
        courseImg.setImageResource(R.drawable.main_course_icon);

        fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.replace(R.id.fragment,new MyFragment());
        fragmentTransaction.commit();
    }
}
